package com.slg.android.listenbook.biz.home.fragment;


import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.slg.android.listenbook.R;
import com.slg.android.listenbook.biz.home.adapter.FMFragmentAdapter;
import com.slg.android.listenbook.configuration.app.MainConstants;
import com.viewpagerindicator.CirclePageIndicator;

/**
 * User: Giotto
 * Date: 2015-03-24
 * Time: 12:55
 */
public class FMFragment extends Fragment implements MainConstants {
    private static final String TAG = FMFragment.class.getSimpleName();
    @ViewInject(R.id.fm_pageIndicator)
    private CirclePageIndicator mIndicator;
    @ViewInject(R.id.fm_viewPager)
    private ViewPager mPager;
    private FMFragmentAdapter mAdapter;

    public FMFragment() {
        // Required empty public constructor
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_fm, container, false);
        ViewUtils.inject(this, view);



        return view;
    }

    @Override
    public void onResume() {
        super.onResume();
        mAdapter = new FMFragmentAdapter(getActivity().getSupportFragmentManager());
        mPager.setAdapter(mAdapter);
        mIndicator.setFillColor(getResources().getColor(R.color.text_red));
        mIndicator.setStrokeColor(getResources().getColor(R.color.gray));
        mIndicator.setPageColor(getResources().getColor(R.color.gray));
        mIndicator.setViewPager(mPager);
    }
    public void handleMessageFormActivity(Intent intent){
        Log.d(TAG,"收到消息");
        mPager.setCurrentItem(0);
        Fragment currentItem = mAdapter.getItem(0);
        if(currentItem instanceof PlayerDetailFragment){
            String data = intent.getStringExtra(DATA_JSON);
            ((PlayerDetailFragment) currentItem).initMusic(data);
        }
    }
}
